package system

import (
	"context"
	"github.com/gogf/gf/v2/errors/gcode"
	"github.com/gogf/gf/v2/errors/gerror"
	"zuhao-seucre/utility/captcha"

	"zuhao-seucre/api/system/v1"
)

func (c *ControllerV1) Captcha(ctx context.Context, req *v1.CaptchaReq) (res *v1.CaptchaRes, err error) {
	id, image, err := captcha.Generate()

	if err != nil {
		err = gerror.NewCode(gcode.CodeOperationFailed, "获取验证码错误")
		return
	}

	res = &v1.CaptchaRes{
		Base64Captcha: image,
		Cid:           id,
	}

	return
}
